package com.ebelter.ty.ui.activity;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;

import com.ebelter.btcomlib.bases.activity.BaseHandleActivity;


public class MonitorBluetoothStatusBaseActivity extends BaseHandleActivity {

    private static final String TAG = "MonitorBluetoothStatusBaseActivity";

    private BluetoothStatusReceiver mReceiver;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mReceiver=new BluetoothStatusReceiver();

        registerReceiver(mReceiver,makeBlueFilters());

    }

    //蓝牙监听需要添加的Action
    private IntentFilter makeBlueFilters(){
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED");
        intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
        intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
        intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        intentFilter.addAction("android.bluetooth.BluetoothAdapter.STATE_OFF");
        intentFilter.addAction("android.bluetooth.BluetoothAdapter.STATE_ON");
        return intentFilter;
    }


    private class BluetoothStatusReceiver extends BroadcastReceiver{
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (TextUtils.isEmpty(action)){
                return;
            }
            bluetoothStationReceive(intent,action);
//            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
//                int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
//                switch (state) {
//                    case BluetoothAdapter.STATE_OFF:
//                        ULog.i(TAG, "STATE_OFF 手机蓝牙关闭");
//                        break;
//                    case BluetoothAdapter.STATE_TURNING_OFF:
//                        ULog.i(TAG, "STATE_TURNING_OFF 手机蓝牙正在关闭");
//                        break;
//                    case BluetoothAdapter.STATE_ON:
//                        ULog.i(TAG, "STATE_ON 手机蓝牙开启");
//                        break;
//                    case BluetoothAdapter.STATE_TURNING_ON:
//                        ULog.i(TAG, "STATE_TURNING_ON 手机蓝牙正在开启");
//                        break;
//                }
//            }
        }
    }

    protected void bluetoothStationReceive(Intent intent,String action){

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        unregisterReceiver(mReceiver);
        mReceiver=null;
    }

    @Override
    protected int loadLayoutById() {
        return 0;
    }



    @Override
    protected void initData() {

    }
}
